package com.rt.tmpt.others.quartz2.jobs;

import com.rt.tmpt.others.quartz2.manager.AutoJobDTO;
import com.rt.tmpt.dto.Result;
import com.rt.tmpt.service.utils.SpringContextHolder;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

//@DisallowConcurrentExecution//有状态的任务需要加上这个注解  
public class BeanObjectJobAction implements Job {  
  
    @Override  
    public void execute(JobExecutionContext arg0) throws JobExecutionException {  
        System.out.println("任务成功运行------");  
        AutoJobDTO jobDto = (AutoJobDTO)arg0.getMergedJobDataMap().get("scheduleJob");  
        System.out.println("任务名称 = [" + jobDto.getJob_name()+ "]");  
        
		//动态调用bean
        Map<String,Object> paramMap = new HashMap<String, Object>();
		Object o = SpringContextHolder.getBean(jobDto.getBeanObject());
		try{
			Method method = o.getClass().getMethod(jobDto.getBeanMethod(),Map.class);
			Result resultObj = (Result)method.invoke( o ,paramMap);
			System.out.println("----------SystemJobAction:"+resultObj.getContent());
		}catch (Exception e) {
			e.printStackTrace();
		}

    }  
  
}  